package com.yuntsg.nnsfcp.util;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.BasicCredentialsProvider;

import java.util.Map;

public class LoadInfoTest {
    //山大代理58.194.172.216
    //广州中医药大学 210.38.102.157:60022
    //广州中医药大学代理:210.38.102.157:10086
    //上交大代理 202.120.23.59
    //潍坊:210.44.82.12:10086
    //长治:59.48.37.141:10086
    //中日友好:47.95.220.101:10086
    public static String IP_ADDRESS = "202.120.23.59";
    public static int IP_PORT = 10086;
    public static String USER = "qf";
    public static String PWD = "qf3.1415";

    public static void init(Map<String, String> map) {
        try {
            USER = map.get("username");
            PWD = map.get("password");
            if (map.get("iport") != null)
                IP_ADDRESS = map.get("iport").split(":")[0];
            if (map.get("iport") != null)
                IP_PORT = Integer.parseInt(map.get("iport").split(":")[1]);
            System.out.println(map.get("gid") + " " + map.get("nid") + " " + USER + " " + PWD + " " + IP_ADDRESS + " " + IP_PORT);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static CredentialsProvider build() {
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(IP_ADDRESS, IP_PORT), (Credentials) new UsernamePasswordCredentials(USER, PWD));
        return credsProvider;
    }

    public static RequestConfig buildRequestConfigure(boolean JumpFlag) {
        RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(10000)
                .setConnectTimeout(10000)
                .setProxy(new HttpHost(IP_ADDRESS, IP_PORT))
//				.setRedirectsEnabled(JumpFlag)
                .build();// 设置请求和传输超时时间
        return requestConfig;
    }

    /**
     * redirectFlag作为
     */
    public static RequestConfig buildRequestConfigureNoProxy() {
        RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(10000)
                .setConnectTimeout(10000)
                .build();// 设置请求和传输超时时间
        return requestConfig;
    }

    public static RequestConfig buildRequestConfigure1() {
        RequestConfig requestConfig = RequestConfig.custom().setRedirectsEnabled(false)
                .setSocketTimeout(25000).setConnectTimeout(25000).setProxy(new HttpHost(IP_ADDRESS, IP_PORT))
                .build();// 设置请求和传输超时时间
        return requestConfig;
    }
}
